package wyq.gy.Tool;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;

public  class util {
    public static boolean isNetworkAvailable(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        //新版本调用方法获取网络状态
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Network[] networks = connectivityManager.getAllNetworks();
            NetworkInfo networkInfo;
            for (Network mNetwork : networks) {
                networkInfo = connectivityManager.getNetworkInfo(mNetwork);
                if (networkInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
                    return true;
                }
            }
        }else {
            //否则调用旧版本方法
            if (connectivityManager != null) {
                NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
                if (info != null) {
                    for (NetworkInfo anInfo : info) {
                        if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    public static String GetStatusText(String statusId){
        String ret = "刚发布";
        switch (statusId){
            case "1":
                ret = "刚发布";
                break;
            case "2":
                ret = "已接单";
                break;
            case "3":
                ret = "雇主确认开始";
                break;
            case "4":
                ret = "工人完成";
                break;
            case "5":
                ret = "雇主确认";
                break;
            case "6":
                ret = "全部完成";
                break;
            case "7":
                ret = "已评价";
                break;
            default:
                break;
        }
        return ret;
    }
}
